//server sock
int createServer(int port){
	int listenfd=socket(AF_INET,SOCK_STREAM,0);
	struct sockaddr_in sockwn;
	sockwn.sin_family=AF_INET;
	sockwn.sin_port=htons(port);
	sockwn.sin_addr.s_addr=htonl(INADDR_ANY);
	bind(listenfd,(struct sockaddr*)&sockwn,sizeof(sockwn));
	listen(listenfd,10);
	printf("端口已暴露:%d\n",port);
	return listenfd;
}

//client sock
//连接到socket服务器
int connToServer(char *ip,int port){
	//create socket
	int cfd=socket(AF_INET,SOCK_STREAM,0);
	//create saddr
	struct sockaddr_in saddr;
	saddr.sin_family=AF_INET;
	saddr.sin_port=htons(port);
	inet_pton(AF_INET,ip,&saddr.sin_addr.s_addr);
	int slen=sizeof(saddr);
	//connect
	connect(cfd,(struct sockaddr *)&saddr,slen);
	return cfd;
}

//发送指令到服务器并接收响应
void sendCmdToSrv(char *ip,int port,char *cmd,int cmdlen,char *resp,int resplen){
	int cfd=connToServer(ip,port);
	int a=write(cfd,cmd,cmdlen);
if(a<=0){
printf("write erro:%d\n",a);
}
	int b=read(cfd,resp,resplen);
if(b<=0){
printf("read erro:%d\n",b);
}
	close(cfd);
}


void freeStrArr(char **strArr,int len){
	for(int i=0;i<len;i++){
		free(strArr[i]);
		strArr[i]=NULL;
	}
	free(strArr);
	strArr=NULL;
}




